package com.derbysoft.ota.infrastructure.springws.soap.server.endpoint;

import org.springframework.ws.soap.server.endpoint.SoapFaultDefinition;
import org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver;

public class NeverNullSoapFaultMappingExceptionResolver extends SoapFaultMappingExceptionResolver {

	public static final String DEFAULT_MESSAGE_WHEN_EMPTY = "Unexpceted error occoured, please check the content of the request xml to insure whether it's correct.";
	
	private String messageWhenEmpty = DEFAULT_MESSAGE_WHEN_EMPTY;

	@Override
	protected SoapFaultDefinition getFaultDefinition(Object endpoint, Exception ex) {
		if (ex.getMessage() != null) {
			return SoapFaultDefinitions.clientFaultOf(ex.getMessage());
		}
		
		SoapFaultDefinition definition = super.getFaultDefinition(endpoint, ex);
		if (definition != null) {
			return definition;
		}
		
		return SoapFaultDefinitions.clientFaultOf(messageWhenEmpty);
	}

	public void setMessageWhenEmpty(String messageWhenEmpty) {
		this.messageWhenEmpty = messageWhenEmpty;
	}
	
	

}
